﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

/// <summary>
/// Summary description for AHMIDEAIdentity
/// </summary>
public class AHMIDEAIdentity : System.Security.Principal.IIdentity
{
    private FormsAuthenticationTicket _ticket;
    private string[] _userDataPieces;

    public AHMIDEAIdentity(FormsAuthenticationTicket ticket)
    {
        _ticket = ticket;
        _userDataPieces = _ticket.UserData.Split("|".ToCharArray());
    }

    public string AuthenticationType
    {
        get { return "Forms"; }
    }

    public bool IsAuthenticated
    {
        get {
            return _userDataPieces.Length>3; 
        }
    }

    public string Name
    {
        get {
            return _userDataPieces[0] + "\\" + _userDataPieces[1]; 
        }
    }
    public FormsAuthenticationTicket Ticket { 
        get { return _ticket; } 
    }
    public string Domain { 
        get { 
            try {
                return _userDataPieces[0];
            }
            catch { }
            return "";
        } 
    }
    public string Username
    {
        get
        {
            try
            {
                return _userDataPieces[1];
            }
            catch { }
            return "";
        }
    }
    public string DisplayName
    {
        get
        {
            try
            {
                return (!string.IsNullOrEmpty(_userDataPieces[2])? _userDataPieces[2] :  _userDataPieces[0] + "\\" + _userDataPieces[1]);
            }
            catch { }
            return "";
        }
    }
    public string Email
    {
        get
        {
            try
            {
                return _userDataPieces[3];
            }
            catch { }
            return "";
        }
    }
    public string Nrp
    {
        get
        {
            try
            {
                return _userDataPieces[4];
            }
            catch { }
            return "";
        }
    }

   
}